#pragma once
#include "DCapsule.h"
#include "../DSpace.h"
#include "../DVector3.h"

namespace Skill
{
	namespace Ode
	{
		namespace Geometries
		{
			DCapsule::DCapsule(DSpace^ space, dReal radius, dReal length)
				:DGeometry(space)
			{
				dSpaceID s = space? space->_Space() : NULL;
				_SetPointer(dCreateCapsule(s,radius,length) ,true);	
				if(_Container)
						_Container->AddSpace(this);
			}

			dReal DCapsule::Radius::get()
			{
				if(IsSpace) return System::Single::NaN;
				dReal r,l;
				dGeomCapsuleGetParams(_Geom(),&r,&l);
				return r;
			}
			void DCapsule::Radius::set(dReal value)
			{
				if(IsSpace) return;
				dReal r,l;
				dGeomCapsuleGetParams(_Geom(),&r,&l);
				r = value;
				dGeomCapsuleSetParams(_Geom(),r,l);
			}

			dReal DCapsule::Length::get()
			{
				if(IsSpace) return System::Single::NaN;
				dReal r,l;
				dGeomCapsuleGetParams(_Geom(),&r,&l);
				return l;
			}
			void DCapsule::Length::set(dReal value)
			{
				if(IsSpace) return;
				dReal r,l;
				dGeomCapsuleGetParams(_Geom(),&r,&l);
				l = value;
				dGeomCapsuleSetParams(_Geom(),r,l);
			}

			void DCapsule::SetParams(dReal radius, dReal length)
			{
				if(IsSpace) return;
				dGeomCapsuleSetParams(_Geom(),radius,length);
			}
			void DCapsule::GetParams([OutAttribute]dReal %radius, [OutAttribute]dReal %length)
			{
				if(IsSpace)
				{
					radius = System::Single::NaN;
					length = System::Single::NaN;
					return;
				}
				dReal r,l;
				dGeomCapsuleGetParams(_Geom(),&r,&l);
				radius = r;
				length = l;
			}

			dReal DCapsule::PointDepth(dReal x, dReal y, dReal z)
			{
				if(IsSpace) return Single::NaN;
				return dGeomCapsulePointDepth(_Geom(),x,y,z);
			}
			dReal DCapsule::PointDepth(DVector3^ p)
			{
				if(IsSpace) return Single::NaN;
				return dGeomCapsulePointDepth(_Geom(),p->_This[0],p->_This[1],p->_This[2]);
			}
		}
	}
}